<template>
  <div class="personalbox">
    <!-- 头部 -->
    <header>
      <div class="left iconfont icon-hanbaocaidan" @click.stop="showsidebar"></div>
      <div class="right iconfont icon-sousuo"></div>
    </header>
    <div class="personaldetail">
      <div class="personalface" v-if="!logint">
        <i class="iconfont icon-gerenzhongxin"></i>
      </div>
      <div class="loginpersonalface" v-if="userinformation.profile" :style="'background:url('+userinformation.profile.avatarUrl+')'"></div>
      <div class="personalname" @click.stop="showlogin" v-if="userinformation.profile">{{nickname}}</div>
      <div class="follow" v-if="userinformation.profile">
        <div class="follws">{{userinformation.profile.follows}}关注</div>
        <div class="followeds">{{userinformation.profile.followeds}}粉丝</div>
        <div class="level">Lv.{{userinformation.level}}</div>
      </div>
    </div>
    <div class="personalicon">
      <div class="iconbigbox">
        <div class="iconbox" @click.stop="showlastplay">
          <i class="iconfont icon-24gf-playCircle"></i>
          <p class="van-ellipsis">最近播放</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-wenjianjia"></i>
          <p class="van-ellipsis">本地/下载</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-shangchuanyunpan"></i>
          <p class="van-ellipsis">云盘</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-yigouactive"></i>
          <p class="van-ellipsis">已购</p>
        </div>
      </div>
      <div class="iconbigbox">
        <div class="iconbox">
          <i class="iconfont icon-haoyou"></i>
          <p class="van-ellipsis">我的好友</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-shoucang"></i>
          <p class="van-ellipsis">收藏和赞</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-boke"></i>
          <p class="van-ellipsis">我的播客</p>
        </div>
        <div class="iconbox">
          <i class="iconfont icon-icon28-07"></i>
          <p class="van-ellipsis">音乐罐子</p>
        </div>
      </div>
    </div>
    <div class="personallike" v-if="userPlaylist[0]" @click.stop="enterPlayList(userPlaylist[0].id)">
      <div class="imgbox">
        <img :src="userPlaylist[0].coverImgUrl" alt />
      </div>
      <div class="centerbox">
        <div class="top">我喜欢的音乐</div>
        <div class="bottom">{{userPlaylist[0].trackCount}}首</div>
      </div>
    </div>
    <div class="personallikeplaylist">
      <div class="topintro">
        <div>创建的歌单（{{userplaylist}}个）</div>
        <div class="secondbox">
          <div>+</div>
          <div>
            <i class="iconfont icon-gengduo"></i>
          </div>
        </div>
      </div>
      <div
        class="listbox"
        @click.stop="enterPlayList(ele.id)"
        v-for="ele in userPlaylist"
        :key="ele.id"
        v-show="ele.id!=627160975&&ele.creator.userId==personalid"
      >
        <div class="imgbox">
          <img :src="ele.coverImgUrl" alt />
        </div>
        <div class="centerbox">
          <div class="top">{{ele.name}}</div>
          <div class="bottom">{{ele.trackCount}}首</div>
        </div>
      </div>
    </div>
    <div class="personalplaylist">
      <div class="topintro" v-if="userinformation.profile">
        <div>收藏的歌单（{{likeplaylist}}个）</div>
        <div class="secondbox">
          <div>
            <i class="iconfont icon-gengduo"></i>
          </div>
        </div>
      </div>
      <div
        class="listbox"
        v-for="ele in userPlaylist"
        @click.stop="enterPlayList(ele.id)"
        :key="ele.id"
        v-show="ele.id!=627160975&&ele.creator.userId!=personalid"
      >
        <div class="imgbox">
          <img :src="ele.coverImgUrl" alt />
        </div>
        <div class="centerbox">
          <div class="top">{{ele.name}}</div>
          <div class="bottom">{{ele.trackCount}}首</div>
        </div>
      </div>
    </div>
    <last-play :show="lastplayshow" @hidelastplayson="hidelastplay"></last-play>
  </div>
</template>

<script>
import lastPlay from "../components/lastplay.vue";
import { getUserInformation } from "../assets/api/personal";
import { getUserPlaylist } from "../assets/api/personal";
export default {
  props: ["personalid", "logint", "face"],
  data() {
    return {
      lastplayshow: false,
      userinformation: {},
      userPlaylist: [],
    };
  },
  components: {
    lastPlay,
  },
  methods: {
    hidelastplay() {
      this.lastplayshow = false;
    },
    showlastplay() {
      console.log("true");
      this.lastplayshow = true;
    },
    showlogin() {
      if (!this.logint) {
        this.$emit("showloginson");
      }
    },
    showsidebar() {
      this.$emit("showsidebarson");
    },
    enterPlayList(id) {
      this.$emit("enter-play-listson", id);
    },
  },
  watch: {
    personalid(newV) {
      getUserInformation({ uid: newV }).then((data) => {
        console.log(this.data);
        this.userinformation = data;
      });
      getUserPlaylist({ uid: newV }).then((data) => {
        console.log(data);
      });
    },
  },
  computed: {
    userplaylist() {
      return this.logint ? this.userPlaylist.length - 1 : 0;
    },
    likeplaylist() {
      return this.logint
        ? this.userPlaylist.length -
            this.userinformation.profile.playlistCount -
            1
        : 0;
    },
    nickname() {
      return this.logint ? this.userinformation.profile.nickname : "立即登录 >";
    },
  },
  created() {
    if (this.personalid) {
      getUserInformation({ uid: this.personalid }).then((data) => {
        this.userinformation = data;
        console.log(this.userinformation);
      });
      getUserPlaylist({ uid: this.personalid }).then((data) => {
        console.log(data);
        this.userPlaylist = data.playlist;
      });
    }
  },
};
</script>

<style lang="less">
.personalbox {
  padding: 0 15px;
}
header {
  margin-top: 49px;
  display: flex;
  height: 35px;
  line-height: 35px;
  justify-content: space-between;
  background: none;
  .left,
  .right {
    flex: 0 0 40px;
    text-align: center;
    color: white;
  }
  .right {
    font-size: 20px !important;
  }
}
.personaldetail {
  margin-top: 54px;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  position: relative;
  padding-top: 49px;
  padding-bottom: 16px;
  box-sizing: border-box;
  .loginpersonalface {
    background-size: cover !important;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    top: -34px;
    overflow: hidden;
  }
  .personalface {
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background-color: white;
    top: -34px;
    overflow: hidden;
    i {
      bottom: 0;
      top: 20px;
      left: 0;
      right: 0;
      width: 65px;
      height: 65px;
      margin: auto;
      font-size: 65px;
      position: absolute;
      color: #f3d7d3;
    }
  }
  .personalname {
    color: white;
    text-align: center;
    font-size: 20px;
  }
  .follow {
    margin-top: 10px;
    display: flex;
    align-items: center;
    height: 23px;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    .follws {
      margin-right: 16px;
    }
    .followeds {
      margin-right: 16px;
    }
    .level {
      align-self: flex-end;
    }
  }
}
.personalicon {
  padding: 25px 28px;
  box-sizing: border-box;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-top: 15px;
  display: flex;
  flex-wrap: wrap;
  .iconbigbox {
    width: 100%;
    display: flex;
    &:nth-child(2) {
      margin-top: 30px;
    }
    .iconbox {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      color: rgba(255, 255, 255, 0.8);
      font-size: 12px;
      margin-right: 27px;
      margin-top: 0;
      padding-bottom: 0;
      border: none;

      &:nth-child(4n) {
        margin-right: 0;
      }
      p {
        margin-top: 8px;
      }
      i {
        font-size: 28px;
        width: 28px;
        height: 28px;
      }
    }
  }
}
.personallike {
  padding: 16px;
  box-sizing: border-box;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-top: 17px;
  display: flex;
  .imgbox {
    border-radius: 8px;
    overflow: hidden;
    width: 48px;
    height: 48px;
    img {
      width: 100%;
    }
  }
  .centerbox {
    flex: 1;
    line-height: 1.5;
    margin-left: 10px;
    padding-top: 5px;
    .top {
      color: white;
      font-size: 14px;
    }
    .bottom {
      color: rgba(255, 255, 255, 0.4);
      font-size: 12px;
    }
  }
}
.personalplaylist {
  padding: 16px;
  box-sizing: border-box;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-top: 17px;
  .topintro {
    display: flex;
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    align-items: center;
    height: 20px;
    justify-content: space-between;
    .secondbox {
      display: flex;
      align-items: center;
      font-size: 20px !important;
      div {
        margin-left: 20px;
      }
      i {
        font-size: 18px;
      }
    }
  }
  .listbox {
    display: flex;
    margin-top: 10px;
    .imgbox {
      border-radius: 8px;
      overflow: hidden;
      width: 48px;
      height: 48px;
      img {
        width: 100%;
      }
    }
    .centerbox {
      flex: 1;
      line-height: 1.5;
      margin-left: 10px;
      padding-top: 5px;
      .top {
        color: white;
        font-size: 14px;
      }
      .bottom {
        color: rgba(255, 255, 255, 0.4);
        font-size: 12px;
      }
    }
  }
}
.personallikeplaylist {
  padding: 16px;
  box-sizing: border-box;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-top: 17px;
  .topintro {
    display: flex;
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    align-items: center;
    height: 20px;
    justify-content: space-between;
    .secondbox {
      display: flex;
      align-items: center;
      font-size: 20px !important;
      div {
        margin-left: 20px;
      }
      i {
        font-size: 18px;
      }
    }
  }
  .listbox {
    display: flex;
    margin-top: 10px;
    .imgbox {
      border-radius: 8px;
      overflow: hidden;
      width: 48px;
      height: 48px;
      img {
        width: 100%;
      }
    }
    .centerbox {
      flex: 1;
      line-height: 1.5;
      margin-left: 10px;
      padding-top: 5px;
      .top {
        color: white;
        font-size: 14px;
      }
      .bottom {
        color: rgba(255, 255, 255, 0.4);
        font-size: 12px;
      }
    }
  }
}
</style>